<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;

class MainController extends Controller
{
    /**
    *判断文件是否存在，并上传
    *
    *@param $pic varchar 上传文件名称
    *@param $request     接受数据的对象
    *@param $arr         要改变的数组
    *@param $path        上传文件存储路径
    *@return $arr        返回改变的数组
    */
    public static function uploadPic($pic, Request $request, $arr, $path="./uploads/images/goods")
    {   
        $ext = $request -> file($pic) -> getClientOriginalExtension();
        $arr[$pic] = time().rand(1000,9999).'.'.$ext;
        $request -> file($pic) -> move($path, $arr[$pic]); 
        return $arr;   
    }
}
